#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>

using namespace std;
int hashKeys[20];
int hashVals[20];
int keysLen;

int findC(void) {
	int c;
	int newc = 1;
	bool conflict=true;
	int restToTimes[20];
	bool hasTimes = false;
	while (conflict) {
		c = newc;
		conflict = false;

		hasTimes =false;
		for (int i=0; i<keysLen; ++i) {
			restToTimes[i] = (hashKeys[i]-c%hashKeys[i])%hashKeys[i];
			if (restToTimes[i] == 0) {
				hasTimes = true;
				break;
			}
		}
// 		cout << "hasTimes: " << hasTimes << endl;
// 		for (int i=0; i<keysLen; ++i)
// 			cout << restToTimes[i] << " ";
// 		cout << endl;
		if (!hasTimes) {
			int smallInc = hashKeys[0];
			for (int i=0; i<keysLen; ++i)
				smallInc = min(smallInc, restToTimes[i]);
			c += smallInc;
		}

		for (int i=0; i<keysLen; ++i)
			hashVals[i] = (c/hashKeys[i]) % keysLen;

		newc = 0;
		for (int i=0; i<keysLen; ++i)
			for (int j=i+1; j<keysLen; ++j)
				if (hashVals[i] == hashVals[j]) {
					conflict = true;
					newc = max(newc, min((c/hashKeys[i]+1)*hashKeys[i],
							(c/hashKeys[j]+1)*hashKeys[j]));
				}
	}
	return c;
}

int main(void)
{
	char line[1000];
	while (true) {
		memset(line, 0, 1000);
		cin.getline(line, 1000);
		if (strlen(line) == 0) break;
		keysLen = 0;
		stringstream ss(stringstream::in | stringstream::out);
		ss << line;
		do {
			string word="";
			ss >> word;
			if (word.length() == 0) break;
// 			cout << "'" << word << "'" << " ";
			int val = 0;
			for (unsigned int i=0; i<word.length(); ++i)
				val = val*32+word[i]-'a'+1;
			hashKeys[keysLen++] = val;
//			cout << val << endl;

		} while (ss);
		if (keysLen==0) break;

		cout << line << endl;
		cout << findC() << endl;
		cout << endl;

	}
	return 0;
}